<?php
/*------------------------------------------------------------------------
# com_vportfolio - Vportfolio component
# ------------------------------------------------------------------------
# author    Vsmart Extensions
# copyright Copyright (C) 2010 www.vsmart-extensions.com. All Rights Reserved.
# @license - http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
# Websites: http://www.vsmart-extensions.com
# Technical Support:  Forum - http://www.vsmart-extensions.com
-------------------------------------------------------------------------*/
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

$url = JURI::base();
?>

<script>
	var autoPublic = <?php echo $this->config->cf_allow_review_auto; ?>;
	function showReviewForm(){
		jQuery("div#reviewForm").show("slow");
	}
	function hideReviewForm(){
		jQuery("div#reviewForm").hide("slow");
	}
	function saveReview() {
		var form = document.adminForm;
		// do field validation
		if (jQuery("#customer").val() == "") {
			inlineMsg('customer','You must enter your name.',2);
		} else if(jQuery("#review").val() == ""){
			inlineMsg('review','You must write review.',2);
		}else{
			jQuery.ajax({
			   type: "POST",
			   async: false,
			   url: "<?php echo $url."/index.php"; ?>",
			   data: "option=com_vportfolio&task=saveReview&id=<?php echo $this->item->id; ?>&review=" + jQuery("#review").val() + "&customer="+jQuery("#customer").val() + "&email=" + jQuery("#email").val(),
			   success: function(html){
				 if(autoPublic == 1){
				 	alert("Thank you for writing us a review!");
					jQuery('#customerReview').append(html);
				 }else{
				 	alert(html);
				 }
				 document.getElementById('review').value = '';
				 document.getElementById('customer').value = '';
				 document.getElementById('email').value = '';
				 jQuery("div#reviewForm").hide("slow");
			   }
			});
		}
	}
</script>
<p>Click <span onclick="showReviewForm();" class="spanLink">here</span> to write a review.</p>
<div id="reviewForm" style="display:none;">
    <table class="admintable" cellspacing="1">
        <tr>
            <td width="150" class="key">
                <label for="tile">
                    <?php echo JText::_( 'Customer' ); ?>
                </label>
            </td>
            <td>
                <input type="text" name="customer" id="customer" class="inputbox" size="40" style="width:200px;" />
            </td>
        </tr>
        <tr>
            <td width="150" class="key">
                <label for="tile">
                    <?php echo JText::_( 'Email' ); ?>
                </label>
            </td>
            <td>
                <input type="text" name="email" id="email" class="inputbox" size="40" style="width:200px;" />
            </td>
        </tr>
        <tr>
            <td width="150" class="key">
                <label for="url">
                    <?php echo JText::_( 'Review' ); ?>
                </label>
            </td>
            <td>
                <textarea name="review" id="review" class="inputbox" cols="30" rows="5" style="width:250px;"></textarea>
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <input type="button"  value="Save" onclick="saveReview();"/>&nbsp;<input type="button" value="Hide" onclick="hideReviewForm();"/>
            </td>
        </tr>
    </table>
</div> 